<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<script type="text/javascript">
	$(function() {
		var cProName = '';
		var cNum = 0;
		var cCode = 0;
		$('#moduls_fun_doDeterPer_datagrid').datagrid({
			url : '${pageContext.request.contextPath}/detContentAction!QueryDetDetailed.action?userId='+moduls_deterPerson_doDeterPerFun_userId,
			fit : true,
			border : false,
			checkOnSelect : false,
			selectOnCheck : false,
			collapsible : true,
			showFooter : true,
			idField : 'contentId',
			nowrap : true,
			columns : [ [ {
				title : '测评项目ID',
				field : 'contentId',
				width : 50,
				hidden : true
			}, {
				title : '测评类型',
				field : 'posType',
				width : 85,
				hidden : true
			}, {
				title : '编号',
				field : 'code',
				width : 25,
				align : 'center',
				formatter : function(value, row, index) {
					if(row.mark || row.mark == 0) {
						return '';
					}
					cCode += 1;
					return cCode;
				}
			}, {
				title : '测评内容',
				field : 'detContent',
				width : 280,
				align : 'center',
				formatter : function(value, row, index) {
					if(row.mark) {
						return '<div align="right" title="'+value+'">' + value + '</div>';
					}
					return '<div align="left" title="'+value+'">' + value + '</div>';
				}
			}, {
				title : '项目平均分',
				field : 'mark',
				align : 'center',
				formatter : function(value, row, index) {
					if(row.mark || row.mark == 0) {
						return row.mark;
					}
					if(row.deteNum ==0) {
						return 0;
					}
					return (row.addupRes / row.deteNum).toFixed(2);
				}
			} ] ],
			onLoadSuccess : function() {
				var rows = $(this).datagrid("getRows");
				var allAddupRes = 0;
				var deteNum = 0;
				for(var i = 0; i < rows.length; i++) {
					allAddupRes += rows[i].addupRes;
					deteNum = rows[i].deteNum;
				}
				var zpjfRes;
				if(deteNum == 0) {
					zpjfRes = 0;
				} else {
					zpjfRes = (allAddupRes / deteNum).toFixed(2);
				}
				$(this).datagrid("reloadFooter", [ {
					detContent : '平均总分',
					mark : zpjfRes
				} ]);
			}
		});

		function getPercent(text, row) {
			var options = $.parseJSON(row.detproOpt);
			var cOptionValue = 0;
			var addupRes = row.addupRes;
			if(options) {
				for ( var i = 0; i < options.length; i++) {
					if (options[i].textField === text) {
						cOptionValue = options[i].valueField * options[i].value;
						break;
					}
				}
			}
			if(addupRes == 0) {
				return 0;
			}
			return (cOptionValue / addupRes * 100).toFixed(2) + '%';
		}

		$.ajax({
			type : 'POST',
			url : '${pageContext.request.contextPath}/deterPersonAction!getDeterPerInfo.action',
			data : {
				posId : moduls_deterPerson_doDeterPerFun_id
			},
			cache : false,
			dataType : 'JSON',
			success : function(r) {
				if(r.duty) {
					var tempStr = '';
					for ( var i = 0; i < r.duty.length; i++) {
						tempStr += (i + 1) + "、" + r.duty[i].pdCont + "<br />";
					}
					$("#doDeterPer_duty").html(tempStr);
				}
			}
		});
		
		$.ajax({
			type : 'POST',
			url : '${pageContext.request.contextPath}/deterPersonAction!getPersSug.action',
			data : {
				userId : moduls_deterPerson_doDeterPerFun_userId
			},
			cache : false,
			dataType : 'JSON',
			success : function(r) {
				if(r) {
					var tempStr = '';
					for ( var i = 0; i < r.length; i++) {
						tempStr += (i + 1) + "、" + r[i].psCont + "<br /><br />";
					}
					$("#doDeterPer_sug").html(tempStr);
				}
			}
		});

		$("#moduls_fun_doDeterPer_psCont").click(function() {
			if ($("#moduls_fun_doDeterPer_psCont").val() == "对Ta的建议........") {
				$("#moduls_fun_doDeterPer_psCont").val("");
			}
		});
		$("#moduls_fun_doDeterPer_psCont").blur(function() {
			if ($("#moduls_fun_doDeterPer_psCont").val() == "") {
				$("#moduls_fun_doDeterPer_psCont").val("对Ta的建议........");
			}
		});
	});

	function moduls_deterPerson_doDeter() {
		var list = [];
		var contRes;
		var item = $("#moduls_fun_doDeterPer_layout_center :radio:checked");
		var rows = $("#moduls_fun_doDeterPer_datagrid").datagrid('getRows');

		if (item.length == rows.length) {
			for ( var i = 0; i < item.length; i++) {
				contRes = new Object();
				contRes.userId = moduls_deterPerson_doDeterPerFun_userId;
				contRes.contentId = item[i].name;
				contRes.detproOpt = item[i].value;
				list.push(contRes);
			}

			////console.info($.toJSON(list));
			var d = $(this).closest('.window-body');

			var psCont = $("#moduls_fun_doDeterPer_psCont").val();
			var detPerId = $("#doDeterPer_detPerId").val();
			if (psCont === '对Ta的建议........') {
				psCont = '';
			}
			$.ajax({
				type : 'POST',
				url : '${pageContext.request.contextPath}/deterPersonAction!doDeter.action',
				data : {
					jsonStr : $.toJSON(list),
					psCont : psCont,
					userId : detPerId
				},
				cache : false,
				dataType : 'JSON',
				success : function(r) {
					//console.info(r.success);
					if (r.success) {
						moduls_deterPerson_doDeterPerFun_div.dialog('destroy');
					}
					$.messager.show({
						msg : r.msg,
						title : '提示'
					});
				}
			});

			//console.info(psCont);
		} else {
			$.messager.show({
				msg : '您还没测评完所有项目！',
				title : '提示'
			});
		}
	}
</script>
<div id="moduls_fun_doDeterPer_layout" class="easyui-layout" data-options="fit:true">
	<div data-options="region:'north', title:'Ta的信息', border:false" style="height: 200px; background-color: #EFEFEF;">
		<div style="height: 100%;">
			<input id="doDeterPer_detPerId" name="detPerId" style="display: none;" hidden="true" />
			<table style="width: 460; border: 0xp;">
				<tr>
					<td width="100" rowspan="4"><img id="fun_doDeterPer_img" src="" width="108" height="129" />
					</td>
					<td width="100" height="25" align="center">姓名:</td>
					<td width="150" height="25"><samp id="doDeterPer_username"></samp>
					</td>
					<td height="25" align="center"></td>
					<td height="25"></td>
				</tr>
				<tr>
					<td height="25" align="center">岗位:</td>
					<td height="25"><samp id="doDeterPer_posId"></samp>
					</td>
					<td height="25" align="center"></td>
					<td height="25"></td>
				</tr>
				<tr>
					<td height="25" align="center">上级:</td>
					<td height="25"><samp id="doDeterPer_personSup"></samp>
					</td>
					<td height="25" align="center"></td>
					<td height="25"></td>
				</tr>
				<tr>
					<td height="25" align="center">下级:</td>
					<td height="25"><samp id="doDeterPer_personSub"></samp>
					</td>
					<td width="100" height="25" align="center">责任对象:</td>
					<td width="150" height="25"><samp id="doDeterPer_dutyObj"></samp>
					</td>
				</tr>
			</table>
			<fieldset>
				<legend>Ta的职责</legend>
				<samp id="doDeterPer_duty"></samp>
			</fieldset>
		</div>
	</div>
	<div id="moduls_fun_doDeterPer_layout_center" data-options="region:'center',border:false, title:'对Ta的测评'">
		<table id="moduls_fun_doDeterPer_datagrid"></table>
	</div>
	<div data-options="region:'south',border:false" style="height: 70px; overflow: hidden;">
	<fieldset>
				<legend>Ta的建议</legend>
				<samp id="doDeterPer_sug"></samp>
			</fieldset>
	</div>
</div>
